﻿# -*- coding: utf-8 -*-
'''
Created on 26.05.2011

@author: Andrey Gaidel
'''

import datetime
import models
from django import forms
from django.contrib.admin import widgets

class PaymentForm(forms.Form):
    
    payment = forms.DecimalField(max_digits=19, decimal_places=2)

class DateForm(forms.Form):
    
    date = forms.DateField(widget=widgets.AdminDateWidget)

class ScholarshipBySemesterForm(forms.Form):
    
    SEMESTER_CHOICES = (
        (0, u"Осенний"),
        (1, u"Весенний")
    )
    YEAR_FORMAT = u"%04d/%04d"
    years = forms.ChoiceField(label=u"Учебный год")
    semester = forms.ChoiceField(choices=SEMESTER_CHOICES, label=u"Номер семестра", widget=forms.RadioSelect)
    
    def __init__(self, *args, **kwargs):
        super(ScholarshipBySemesterForm, self).__init__(*args, **kwargs)
        sessions = list(models.Session.objects.all())
        years = set()
        for session in sessions:
            year = session.start_date.year
            if session.start_date < datetime.date(year, 9, 1):
                year = year - 1
            if session.number & 1 == 0:
                year = year + 1
            years.add((year, ScholarshipBySemesterForm.YEAR_FORMAT % (year, year + 1)))
        years = list(years)
        years.sort(key=lambda x: x[0])
        self.fields['years'].choices = years
        self.fields['years'].initial = years[len(years) - 1][0]

class SendRequestForm(forms.ModelForm):
    
    class Meta:
        model = models.WelfareRequest
        exclude = ('student', 'date')

class SessionResultForm(forms.Form):
    
    group = forms.ModelChoiceField(queryset=models.StudentGroup.objects.all(), label=u"Группа")
    session = forms.ModelChoiceField(queryset=models.Session.objects.all(), label=u"Сессия")

class StudentGroupChoiceForm(forms.Form):
    
    groups = forms.ModelChoiceField(queryset=models.StudentGroup.objects.all(), label=u"Укажите группу")
